package me.sunpeng.java2;

import java.time.LocalDate;
import java.time.temporal.Temporal;

/**
 * @author sp
 * @create 2022-04-28
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Task task = new TaskImpl();
        task.run();
    }


}

class TaskImpl implements Task {
    @Override
    public void run() throws Exception {
        System.out.println("run 接下来抛出异常");

        Comparable<? super LocalDate> comparable = new Comparable<Temporal>() {
            @Override
            public int compareTo(Temporal o) {
                return 0;
            }
        };

    }
}

interface Task {
    void run() throws Exception;

    @SuppressWarnings("unchecked")
    static <T extends Throwable> void throwAs(Throwable t) throws T {
        throw (T) t;
    }

    static Runnable asRunable(Task task) {
        return () -> {
            try {
                task.run();
            } catch (Exception e) {
                Task.<RuntimeException>throwAs(e);
            }
        };
    }
}
